package com.ruoyi.cms.service.impl;

import com.ruoyi.cms.mapper.CIndexMapper;
import com.ruoyi.cms.service.CIndexService;
import com.ruoyi.cms.vo.IndexCountVO;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.mapper.SysConfigMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author Choi
 * @Date 2021/8/25
 */

@Service
public class IndexServiceImpl implements CIndexService {

    @Autowired
    private CIndexMapper cIndexMapper;
    @Autowired
    private SysConfigMapper sysConfigMapper;

    @Override
    public SysConfig clearConfig() {
        SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique("sys.config.clear");
        if (sysConfig == null) {
            //新增
            sysConfig = new SysConfig();
            sysConfig.setConfigName("标记清理缓存");
            sysConfig.setConfigKey("sys.config.clear");
            sysConfig.setConfigValue("true");
            sysConfig.setConfigType("N");
            sysConfigMapper.insertConfig(sysConfig);
        } else {
            sysConfig.setConfigValue("true");
            sysConfigMapper.updateConfig(sysConfig);
        }
        return sysConfig;
    }

    @Override
    public IndexCountVO getCounts() {
        int cityCount = cIndexMapper.getCityCount();
        int displayCount = cIndexMapper.getDisplayCount();
        int logoCount = cIndexMapper.getLogoCount();
        int videoCount = cIndexMapper.getVideoCount();
        return new IndexCountVO(cityCount, displayCount, logoCount, videoCount);
    }
}
